package cs6238.common;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class Configuration {
	public static final String SERVER_ADDRESS = "server_address";
	public static final String NETWORK_PORT = "network_port";
	
	public static final String KEYSTORE_PATH = "keystore_path";
	public static final String KEYSTORE_PASSWORD = "keystore_password";
	public static final String TRUSTSTORE_PATH = "truststore_path";
	public static final String TRUSTSTORE_PASSWORD = "truststore_password";
	
	public static final String CLIENT_CERT_FOLDER_PATH = "client_cert_folder_path";
	public static final String CLIENT_FILE_FOLDER_PATH = "client_file_folder_path";
	
	
	private static final String CLIENT_PROPERTIES_FILE = "config/client.properties";
	private static final String COMMON_PROPERTIES_FILE = "config/common.properties";
	private static final String SERVER_PROPERTIES_FILE = "config/server.properties";
	

	private Properties _prop;
	
	private Configuration(String ... filenames){
		_prop = new Properties();
		try {
			for(String filename : filenames){
				_prop.load(new FileInputStream(filename));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static Configuration loadClientSettings(){
		return new Configuration(CLIENT_PROPERTIES_FILE, COMMON_PROPERTIES_FILE);
	}
	
	public static Configuration loadServerSettings(){
		return new Configuration(SERVER_PROPERTIES_FILE, COMMON_PROPERTIES_FILE);
	}
	
	public String getSetting(String setting){
		return _prop.getProperty(setting);
	}
	
	public int getSettingAsInt(String setting){
		return Integer.parseInt(_prop.getProperty(setting));
	}
}
